//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: {},
    //nav标志
    navFlag: 0,
    loanIndex: 0,
    money: {
      hma: "",
      ni: "",
      cf: "",
      mc: "",
      rate:"100",
      over_price: "0"
    },
  
    result: {
      total: "0.000",
    }
  },
  onLoad: function () {
    
  },
  submit: function () {
    if(!this.data.money.hma){
        wx.showToast({
            title: '请输入HMA参数',
            icon: 'none'
        });
        return;
    }
    else if(!this.data.money.ni){
        wx.showToast({
            title: '请输入NI参数',
            icon: 'none'
        });
        return;
    }
    else if(!this.data.money.mc){
        wx.showToast({
            title: '请输入MC参数',
            icon: 'none'
        });
        return;
    }
    
    var that = this;
    var payment = Number(this.data.money.hma) * Number(this.data.money.ni) * 0.01 * Number(this.data.money.cf) * 0.01 * (100 - Number(this.data.money.mc))* 0.01 * Number(this.data.money.rate) * 0.01 + Number(this.data.money.over_price);
    var key = "result.total";
    that.setData({
        [key]: payment.toFixed(3),
    });
  },
  hmaInput: function (e) {
    var that = this;
    var value = e.detail.value;
    var key = "money.hma";
    that.setData({
        [key]: value
    });
  },
  niInput: function (e) {
    var that = this;
    var value = e.detail.value;
    var key1 = "money.ni";
    var key2 = "money.cf";
    var cf = Number(value) * 10 + 1;
    that.setData({
        [key1]: value,
        [key2]: cf.toFixed(3)
    });
  },
  cfInput: function (e) {
    var that = this;
    var value = e.detail.value;
    var key = "money.cf";
    that.setData({
        [key]: value
    });
  },
  mcInput: function (e) {
    var that = this;
    var value = e.detail.value;
    var key = "money.mc";
    that.setData({
        [key]: value
    });
  },
  rateInput: function (e) {
    var that = this;
    var value = e.detail.value;
    var key = "money.rate";
    that.setData({
        [key]: value
    });
  },
  overPriceInput: function (e) {
    var that = this;
    var value = e.detail.value;
    var key = "money.over_price";
    that.setData({
        [key]: value
    });
  },
  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '嘉曼矿价计算器',
      path: '/pages/index/index',
      imageUrl: '../../images/logo.png',
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  }
})
